package cn.hl.sfzy.service.impl;

import cn.hl.sfzy.entity.Article;
import cn.hl.sfzy.entity.Articletype;
import cn.hl.sfzy.entity.Consult;
import cn.hl.sfzy.entity.Course;
import cn.hl.sfzy.mapper.ArticleMapper;
import cn.hl.sfzy.mapper.ArticletypeMapper;
import cn.hl.sfzy.mapper.ConsultMapper;
import cn.hl.sfzy.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ArticleServiceImpl
 * @Description TOOO
 * @Author Lilysi
 * @Date 2024//10//21//11:39
 * @Version 1.0
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private ArticletypeMapper articletypeMapper;
    @Autowired
    private ConsultMapper consultMapper;

    @Override
    public List<Article> getArticles(Article article) {
        List<Article> select = articleMapper.select(article);
        return select;
    }

    @Override
    public int deleteArticle(Long id) {
        int delete = articleMapper.delete(id);
        return delete;
    }

    @Override
    public int deleteType(Long id) {
         int i = articleMapper.deleteType(id);
        return i;
    }

    @Override
    public int addArticle(Article article) {
        int insert = articleMapper.insert(article);
        return insert;
    }

    @Override
    public int updateid(Long id,Long o) {
        int updateid = articleMapper.updateid( id,o);
        return updateid;
    }

    @Override
    public int updateArticle(Article article) {
        int update = articleMapper.update(article);
        return update;
    }

    @Override
    public PageInfo<Article> findByPage(int pageNum, int pageSize,Article article) {
        PageHelper.startPage(pageNum, pageSize);
        List<Article> select = articleMapper.select(article);
        for(Article at : select){
           Long id = at.getType_id();
            Articletype articletypes = articletypeMapper.selectById(id);
            at.setArticletype(articletypes);
        }
        for(Article at : select){
            Long id = at.getTeacher_id();
            Consult consult = consultMapper.selectById(id);
            at.setConsult(consult);
        }
        PageInfo<Article> articlePageInfo = new PageInfo<>(select);
        return articlePageInfo;
    }

    @Override
    public PageInfo<Article> selectByConsultId(int pageNum, int pageSize, Long teacher_id) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Article> info = new PageInfo<>(articleMapper.selectByConsultId(teacher_id));
        return info;
    }

    @Override
    public PageInfo<Article> selectAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Article> info = new PageInfo<>(articleMapper.selectAll());
        return info;
    }
}
